package com.dman.multi.ui.comp;

import java.util.List;

import org.apache.pivot.util.ListenerList;
import org.apache.pivot.wtk.Component;
import org.apache.pivot.wtk.Orientation;

public class PiecewiseMeter extends Component{
	private static class PiecewiseMeterListenerList extends ListenerList<PiecewiseMeterListener>
		implements PiecewiseMeterListener{

		@Override
		public void orientationChanged(PiecewiseMeter meter) {
			for(PiecewiseMeterListener pml: this){
				pml.orientationChanged(meter);
			}
		}

		@Override
		public void sectionPercentagesChanged(PiecewiseMeter meter,
				List<Range> rangeList) {
			for(PiecewiseMeterListener pml: this){
				pml.sectionPercentagesChanged(meter, rangeList);
			}
		}
		
	}
	
	private List<Range> listOfRanges = null;
	private Orientation orientation = null;
	private PiecewiseMeterListenerList piecewiseMeterListeners = new PiecewiseMeterListenerList();
	
	public PiecewiseMeter() {
		this(Orientation.HORIZONTAL);
	}
	
	public PiecewiseMeter(Orientation orientation){
		this.orientation = orientation;
		installSkin(PiecewiseMeter.class);
	}
	
	public List<Range> getListOfRanges(){
		return listOfRanges;
	}
	
	public void setListOfRanges(List<Range> listOfRanges){
		this.listOfRanges = listOfRanges;
	}
	
    public Orientation getOrientation() {
        return orientation;
    }

    public void setOrientation(Orientation orientation) {
        if (orientation == null) {
            throw new IllegalArgumentException("orientation is null.");
        }

        if (this.orientation != orientation) {
            this.orientation = orientation;
            piecewiseMeterListeners.orientationChanged(this);
        }
    }

    public ListenerList<PiecewiseMeterListener> getPiecewiseMeterListeners() {
        return piecewiseMeterListeners;
    }
}
